var db = require('./db');
var tool = require('../tool');

function add(title, content, callback) {
    var add = 'INSERT INTO article (`title`,`content`)  VALUES ('
        + tool.sqlstring(title ) + ',' + tool.sqlstring(content) + ')';
         db.dbExecuteSql(add, function (err, value) {
        if (!err) {
            callback(null, 'suess');
        }
        else {
            callback(err, null);
        }
    });
}
 function getAriticleTitle(callback){
      var sql = 'select title from article';

      db.dbExecuteSql(sql,function(err,result){

      if(!err){
            callback(err,result);
       }
       else{
           callback(err,result);
       }
     });
 }

 function getAriticleContent(id,callback){
    var sql = 'select * from article where id ='+id;
     db.dbExecuteSql(sql,function(err,result){
         console.log(sql,err,result);
        if(!err){
             callback(err,result);
         }
         else{
             callback(err,result);
         }
     });
 }
exports.add = add;
exports.getAriticleTitle= getAriticleTitle;
exports.getAriticleContent = getAriticleContent;